<template>
	<view class="infosw">
		<view v-if="lowerList.length==0" class="noData"><noData></noData></view>
		<view v-else class="list" v-for="item in lowerList" @click="userswitch(item.aid)">
			<view class="listLeft">
				<image :src="item.photo"></image>
				<view>
					<view class="listName">{{item.realname}}</view>
					<view class="listAid">AID: {{item.aid}}</view>
				</view>
			</view>
			<image class="listRight" src="../../static/img/my_back.png" mode=""></image>
		</view>
	</view>
</template>

<script>
	import { userswitchlist, userswitch } from '../../api/index.js'
	import noData from '../../components/data/nodata.vue'
	export default {
		data() {
			return {
				lowerList:[]
			}
		},
		onLoad:function(){
			this.getUserswitchlist();
		},
		methods: {
			getUserswitchlist(){
				let that = this;
				userswitchlist().then((res)=>{
					console.log(res);
					if(res.code == 0){
						that.lowerList = res.data;
					}else{
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				}).catch((e)=>{
					console.log(e);
				})
			},
			async userswitch(aid){
				let that = this;
				try{
					let data = await userswitch({"userid":aid});
					console.log(data);
					uni.showModal({
						title:'提示',
						content: data.msg,
						complete:function(){
							if(data.code == 0){
								that.$storage('global').setItemSync(
								'loginInfo',{token:data.data.login_token,sid:data.data.sid,'aid':data.data.aid},
								);
								that.$store.dispatch('global/setUser'); //vuex执行获取当前用户信息的方法(刷新当前用户)
								uni.switchTab({
									url: '../my/my',
									success: function(e) {
									 //    let page = getCurrentPages().pop();
									 //    if (page == undefined || page == null) return;
										// page.onLoad();
									}
								});
							}
						}
					})
				}catch(e){
					//TODO handle the exception
					console.log(e)
				}
			}
		},
		components:{
			noData
		}
	}
</script>
<style lang="scss" scoped>
	.infosw{
		padding: 0 30rpx;
		.noData{
			padding-top: 100rpx;
		}
		.list{
			display: flex;
			justify-content: space-between;
			align-items: center;
			padding: 30rpx 0;
			border-bottom: 1rpx $uni-solid-color solid;
			.listLeft{
				display: flex;
				.listName{
					font-size: $uni-font-size-lg;
					font-weight: bold;
				}
				.listAid{
					font-size: $uni-font-size-sm;
					color: $uni-text-color-grey;
				}
				image{
					width: 81rpx;
					height: 81rpx;
					border-radius: 100%;
					margin-right: 30rpx;
				}
			}
			.listRight{
				width: 36rpx;
				height: 36rpx;
			}
		}
	}
</style>
